<script language="JavaScript">
<!-- 

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

function buildURL(fld)
{
	if (fld == "") return false;
	var encodedField = "";
	var s = fld;
	if (typeof encodeURIComponent == "function")
	{
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		encodedField = encodeURIComponent(s);
	}
	else 
	{
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		encodedField = encodeURIComponentNew(s);
	}
	alert ("New encoding: " + encodeURIComponentNew(fld) +
		 "\n           escape(): " + escape(fld));
	return true;
}
// -->

</script>

<?php 

  $querymsg="SELECT ID,NickName,Avatar,FirstName,LastName FROM Profiles WHERE ID=$mioid";
  $resultmsg = mysql_query($querymsg,$db) or die(mysql_error());
  $rowmsg = mysql_fetch_row($resultmsg);
  
  if ($varlink!=FALSE OR $varlinkhome!=FALSE OR $pagina=='/') 
  {
   if ($viewnkname=="OFF") {echo '<div id="msgrapido">';}
   elseif ($viewnkname=="ON") {echo '<div id="msgrapidosinick">';}
   if($viewavatar=='ON') 
   { 
    if ($rowmsg[2]==0) 
	{ 
	 $ottieniID=(int)$_COOKIE['memberID'];
	 $valoriutente = getProfileInfo($ottieniID);
	 if ($valoriutente['Sex']=="female") { echo '<img src="/templates/base/images/icons/woman_medium.gif">'; }
     else { echo '<img src="/templates/base/images/icons/visitor_medium.gif">';}
	}
    else {echo '<img src="'.BX_AVA_URL_USER_AVATARS.$rowmsg[2].BX_AVA_EXT.'">';}
	
	
	
   }
   
   if($usernameformat == 0) { $nicknick = $rowmsg[1]; }
   elseif($usernameformat == 1) { $nicknick = $rowmsg[3].' '.$rowmsg[4]; }
   elseif($usernameformat == 2) { $nicknick = $rowmsg[3]; }
   
   if ($viewnkname=='ON') {echo '<div style="100%"><p class="msguser">'.$nicknick.'</p>';}
  
   echo '<script>
   function setbg(color)
   {
     document.getElementById("styled").style.background=color
   }
   </script>';					
   echo '<form name="frm1" id="messaggioajax" method="post"><textarea style="overflow: auto;" name="messaggio"';
   if($viewavatar=='ON') {echo ' class="areamsg"';}
   else { echo ' class="areamsgnoava"';}
   echo ' onclick="if ((this.value!==\'\') && (this.value==\''._t("_ibdw_spywall_msgformhome").'\')){resettaform()};" onfocus="trim1(this);" onblur="if (this.value==\'\'){ritornanormale2()};trim1(this);" onkeypress="trim1(this);return imposeMaxLength(this, '.$messlength.');" onkeyup="trim1(this);"></textarea>
   <input id="user" type="hidden" name="user" value="'; echo $userid; echo '"/>
   <input id="pagina" type="hidden" name="pagina" value="'; echo $pagina; echo '"/>
   <div onclick="inviamessaggiopersonale()" id="submsg">'._t('_ibdw_spywall_send').'</div>
   </form></div>';
   if ($viewnkname=='ON') {echo '</div>';}
  }
  
  else 
  //PAGINA DEL PROFILO
  {
   if($usernameformat == 0) { $nicknick = $rowmsg[1]; }
   elseif($usernameformat == 1) { $nicknick = $rowmsg[3].' '.$rowmsg[4]; }
   elseif($usernameformat == 2) { $nicknick = $rowmsg[3]; }
   
   echo '<div id="msgrapidosinick">';
   if($viewavatar=='ON') 
   {
    if ($rowmsg[2]==0) {echo '<img src="'.$imagepath.'0.jpg" />';}
	else {echo '<img src="modules/boonex/avatar/data/images/'.$rowmsg[2].'.jpg">';}
   }
   if ($mioid==$userid) {echo '<p class="msguser">'._t("_ibdw_spywall_mywall").'</p>';}
   else {echo '<p class="msguser">'._t("_ibdw_spywall_wallof").$nicknick._t("_ibdw_spywall_wallprofile").'</p>';}
   
   echo '<script>
   function setbg(color)
   {
    document.getElementById("styled").style.background=color
   }
   </script>';
   echo '<form name="frm2" id="messaggioajaxd" method="post"><textarea style="overflow:auto;" name="messaggio"';
   if($viewavatar=='ON') {echo ' class="areamsg"';}
   else { echo ' class="areamsgnoava"';}
   echo ' onclick="if ((this.value!==\'\') && (this.value==\''. _t("_ibdw_spywall_msgformhome").'\')){resettaform()};" onfocus="trim2(this);" onblur="if (this.value==\'\'){ritornanormale2()};trim2(this);" onkeypress="trim2(this);return imposeMaxLength(this, '.$messlength.');" onkeyup="trim2(this);"></textarea>
   <input id="invia" type="hidden" name="invia" value="'; echo $userid; echo '"/>
   <input id="riceve" type="hidden" name="riceve" value="'; echo $mioid; echo '"/>
   <input id="pagina" type="hidden" name="pagina" value="'; echo $pagina; echo '"/>
   <div onclick="inviamessaggiopersonalewall()" id="submsg">'._t('_ibdw_spywall_send').'</div>
   </form></div>';
  }
?>